package com.wangsd.web.coupon.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.coupon.entity.Config;
import com.wangsd.web.coupon.entity.SignConfig;
import com.wangsd.web.coupon.entity.SignConfigDetail;
import com.wangsd.web.coupon.service.SignConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author generator
 * @since 2019-10-15
 */
@Api(value = "小程序签到管理", tags = "小程序签到管理")
@RestController
@RequestMapping("/coupon/signConfig")
public class SignConfigController {

    @Autowired
    SignConfigService signConfigService;

    @ApiOperation(value = "查询列表", notes = "查询列表", httpMethod = "POST")
    @PostMapping("/selectList/{pageNum}/{pageSize}")
    public Result selectList(@PathVariable Integer pageNum,
                             @PathVariable Integer pageSize,
                             @RequestBody SignConfig query) {
        IPage<SignConfig> signConfigIPage = signConfigService.selectPage(pageNum, pageSize, query);
        return Result.success(signConfigIPage);
    }

    @ApiOperation(value = "小程序签到管理修改和保存", notes = "小程序签到管理修改和保存", httpMethod = "POST")
    @PostMapping("/save")
    public Result save(@RequestBody SignConfig entity) {
        if (entity.getCompanyId() == null) {
            return Result.fail("商圈不能为空！");
        }
        if (entity.getDefaultPoint() == null) {
            return Result.fail("默认积分！");
        }
        if (entity.getBeginTime() == null) {
            return Result.fail("开始日期！");
        }
        if (entity.getEndTime() == null) {
            return Result.fail("结束日期！");
        }
        signConfigService.addOrUpdate(entity);
        return Result.success();
    }

    @ApiOperation(value = "删除商圈签到配置", notes = "删除商圈签到配置", httpMethod = "GET")
    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        signConfigService.removeById(id);
        return Result.success();
    }

    @ApiOperation(value = "根据商圈签到配置id 查询签到明细", notes = "根据商圈签到配置id 查询签到明细", httpMethod = "GET")
    @GetMapping("/selectDetailBySignConfigId/{id}")
    public Result selectDetailBySignConfigId(@PathVariable Long id) {
        List<SignConfigDetail> signConfigDetails = signConfigService.selectDetailBySignConfigId(id);
        return Result.success(signConfigDetails);
    }

    @ApiOperation(value = "查询所有商圈的签到配置", notes = "查询所有商圈的签到配置", httpMethod = "GET")
    @GetMapping("/selectAll")
    public Result selectAll() {
        List<SignConfig> signConfigs = signConfigService.list();
        return Result.success(signConfigs);
    }

    @ApiOperation(value = "商圈签到上下架操作", notes = "商圈签到上下架操作", httpMethod = "POST")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody SignConfig signConfig) {
        signConfigService.updateStatus(signConfig);
        return Result.success();
    }
}

